import request from './request';

// 试卷相关API接口

/**
 * 创建试卷
 * @param paper 试卷信息
 * @returns Promise
 */
export function createPaper(paper: any) {
  return request({
    url: '/api/paper',
    method: 'post',
    data: paper
  });
}

/**
 * 获取试卷详情
 * @param id 试卷ID
 * @returns Promise
 */
export function getPaperById(id: number) {
  return request({
    url: `/api/paper/${id}`,
    method: 'get'
  });
}

/**
 * 获取所有试卷
 * @returns Promise
 */
export function getAllPapers() {
  return request({
    url: '/api/paper',
    method: 'get'
  });
}

/**
 * 搜索试卷
 * @param params 搜索参数
 * @returns Promise
 */
export function searchPapers(params: any) {
  return request({
    url: '/api/paper/search',
    method: 'get',
    params
  });
}

/**
 * 更新试卷
 * @param paper 试卷信息
 * @returns Promise
 */
export function updatePaper(paper: any) {
  return request({
    url: '/api/paper',
    method: 'put',
    data: paper
  });
}

/**
 * 删除试卷
 * @param id 试卷ID
 * @returns Promise
 */
export function deletePaper(id: number) {
  return request({
    url: `/api/paper/${id}`,
    method: 'delete'
  });
}

/**
 * 为试卷添加题目
 * @param paperId 试卷ID
 * @param paperQuestions 题目列表
 * @returns Promise
 */
export function addQuestionsToPaper(paperId: number, paperQuestions: any[]) {
  return request({
    url: `/api/paper/${paperId}/questions`,
    method: 'post',
    data: paperQuestions
  });
}

/**
 * 获取试卷的所有题目
 * @param paperId 试卷ID
 * @returns Promise
 */
export function getPaperQuestions(paperId: number) {
  return request({
    url: `/api/paper/${paperId}/questions`,
    method: 'get'
  });
}

/**
 * 删除试卷中的所有题目
 * @param paperId 试卷ID
 * @returns Promise
 */
export function deletePaperQuestions(paperId: number) {
  return request({
    url: `/api/paper/${paperId}/questions`,
    method: 'delete'
  });
}

/**
 * 从试卷中删除指定的题目
 * @param paperId 试卷ID
 * @param questionId 题目ID
 * @returns Promise
 */
export function removeQuestionFromPaper(paperId: number, questionId: number) {
  return request({
    url: `/api/paper/${paperId}/questions/${questionId}`,
    method: 'delete'
  });
}
